-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Popover] Refactor popover transition - separation of concerns #7720
[Popover] Refactor popover transition - separation of concerns #7720
Conversation
NOTE: I have seen cross-contamination of tests when run sequentially. I could use some help with that. Individually, tests are passing and the Grow.spec.js in fact never uses the value I have changed all references to
|
…ross contamination
This appears to be stubbed and perhaps never unstubbed:
|
@oliviertassinari this recently changed from a styleManagerMock = wrapper.context('styleManager');
styleManagerMock.theme.transitions.getAutoHeightDuration = stub().returns('woof');
wrapper.setContext({ styleManager: styleManagerMock });
wrapper.setProps({ transitionDuration: 'auto' });
instance = wrapper.instance(); Now: theme = instance.props.theme;
theme.transitions.getAutoHeightDuration = stub().returns('woofCollapseStub');
wrapper.setProps({ transitionDuration: 'auto' });
instance = wrapper.instance(); Either we need to regenerate theme so it is pristine on each |
I added an explicit restore of the stubbed method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of this PR. It's a quick review, I need to have a deeper look this evening :).
src/internal/Popover.js
Outdated
@@ -200,7 +200,7 @@ type AllProps = DefaultProps & Props; | |||
/** | |||
* @ignore - internal component. | |||
*/ | |||
class Popover extends Component<DefaultProps, AllProps, void> { | |||
class Popover extends PureComponent<DefaultProps, AllProps, void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The component takes a children, let's keep Component.
src/transitions/Grow.js
Outdated
/** | ||
* @ignore - internal component. | ||
*/ | ||
class Grow extends PureComponent<DefaultProps, AllProps, void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The component takes a children, PureComponent is harming the performance, let's use to Component.
I've confirmed the |
Feel free to ping me if you need help or more info about |
Thanks @FezVrasta - hope you are well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a deep look into it. That looks great 😄 .
@@ -479,7 +411,7 @@ class Popover extends Component<DefaultProps, AllProps, void> { | |||
<EventListener target="window" onResize={this.handleResize} /> | |||
{children} | |||
</Paper> | |||
</Transition> | |||
</Grow> | |||
</Modal> | |||
); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove all the occurrences of withTheme
and theme
in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still need it in #handleEnter for theme.transitions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was looking at the wrong file, you are right.
@@ -449,24 +381,24 @@ class Popover extends Component<DefaultProps, AllProps, void> { | |||
...other | |||
} = this.props; | |||
|
|||
// FIXME: props API consistency problem? - `...other` not spread over the root |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, let's move the ...other to the root. What's preventing us from doing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing yet, just want to save that for the next wave of the refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
} | ||
|
||
type DefaultProps = { | ||
theme: Object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This property is injected by withTheme()
, I don't think that we need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
necessary for flow resolution. We could add it to AllProps
instead, but that would differ from the pattern in other files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't making the property required allow us to remove it here? It's the same for the classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has to be required somewhere, and it is not required outside this component. If it is not required outside the component, we cannot require it in export type Props
, as it would prohibit using the type externally to compose components.
/** | ||
* @ignore | ||
*/ | ||
theme?: Object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it should be required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not required externally (maybe type), but it is internally, that's why it's optional in Props
and required in DefaultProps
. The intersection of these mean internally the component can expect it to be non-null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the same thing with the classes
? I have put them required in the code, but in the documentation I have change them to be optional. Anyway here it's not documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as classes
, see above for explanation. It's all about externalizing Props for reuse. If theme isn't allowed to be passed in (by the user), we should remove it from Props
.
src/transitions/Grow.js
Outdated
import Transition from '../internal/Transition'; | ||
import type { TransitionCallback } from '../internal/Transition'; | ||
|
||
export function getScale(value: number) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add // Only exported for the tests
.
I'm not that sure about it. The |
This can be done with popper, even the custom positioning with a modifier. I'm not too keen to take that on yet. I've got a lot on my plate, but it is certainly viable and I think it would cut code and rely on a good external project. |
@rosskevin Great, it's much better with the concerns separated :). |
* upstream/v1-beta: (24 commits) v1.0.0-beta.5 Update CHANGELOG.md [CHANGELOG] Prepare v1.0.0-beta.5 chore(package): update size-limit to version 0.9.0 (mui#7757) [docs] Fix yarn docs:build script (mui#7745) [docs] Update the readme [Radio] Fix accessibility issue (mui#7742) [Tabs][BottomNavigation] Use value over index property (mui#7741) [core] Remove createStyleSheet (mui#7740) [core] Start simplifying styling API (mui#7730) [LinearProgress] Use transform instead width (mui#7732) Fix Typo (mui#7736) Documentation Fix - Fixing up the README documentation (mui#7733) [ButtonBase] Expose internal component (mui#7727) [Popover] Refactor popover transition - separation of concerns (mui#7720) Button documentation fix (mui#7726) Update supported-components.md (mui#7722) chore(package): update webpack to version 3.5.3 (mui#7723) [flow] flow type transitions Slide, Fade, Collapse (fixes) Create CODE_OF_CONDUCT.md ...
squash+merge
For simplification and external reuse of the
Popover
transition (now calledGrow
) withreact-autosuggest
, I have refactoredPopover
.Popover
is currently used exclusively byMenu
.As it stands, here are the purposes:
internal/Popover
= positioning +Modal
+Grow
+Paper
(used byMenu
)transitions/Grow
= only the effect exhibited by popovers - grow with a bit of fade in.There are also various small fixes I encountered as I refactored.
I should also mention that this is possibly the lead-in to deleting the positioning code in
Popover
in lieu of usingreact-popper
, but I'll wait to take that on after I've used it a bit withreact-autosuggest
.